/**
 * 
 */
package com.nwpusp.model.barrier;

import com.nwpusp.model.Entity;
import com.nwpusp.model.EntityClassifyManager;
import com.nwpusp.model.EntityContainer;
import com.nwpusp.model.TrackManager;
import com.nwpusp.model.location.Axis;
import com.nwpusp.model.location.Size;
import com.nwpusp.model.props.Prop;

/**
 * @author JustinCao
 *
 */
public class BarrierManager extends EntityClassifyManager {
	
	public BarrierManager(EntityContainer globalContainer, TrackManager trackMgr) {
		super(globalContainer, trackMgr);
	}
	
	private int seidCnt = 0;
	synchronized private int increaseSeidCnt() {
		return seidCnt++;
	}
	
	public boolean add(Entity e) {
		if(e instanceof Barrier) {
			return super.add(e);
		}
		return false;
	}
	
	public boolean remove(Entity e) {
		if(e instanceof Barrier) {
			return super.remove(e);
		}
		return false;
	}
	
// Interface for new Barrier {
	public void allocBarrier(Axis pos) {
		allocBarrier(pos, new Size(200, 2000, 2000));
	}

	public void allocBarrier(Axis pos, Size size) {
		appendBarrier(pos, size, increaseSeidCnt());
	}

	public void appendBarrier(Axis pos, Size size, int seid) {
		Barrier b = new Barrier(seid);
		b.setPosition(pos);
		b.setSize(size);
		add(b);
	}
		
	synchronized public Barrier getBarrierBySeid(int seid) {
		for(Entity b : this) {
			if(((Barrier)b).getStaticEntityId() == seid) {
				return (Barrier)b;
			}
		}
		return null;
	}

	public void removeBarrier(int seid) {
		Barrier b = getBarrierBySeid(seid);
		if(b != null) {
			remove(b);
		}
	}
// } Interface for new Barrier

	public void Init() {
		seidCnt = 0;
	}
}
